<template>
  <div class="center">
    <div class="up">
      <div class="bg-color-black item">
        <p class="ml-3 colorBlue fw-b" style="text-align:center;">车辆的总数量</p>
        <div style="text-align:center ; line-height: 30px; font-size: 16px;">
          {{ result.sumCar }}
        </div>
      </div>
       <div class="bg-color-black item">
          <p class="ml-3 colorBlue fw-b" style="text-align:center;">销售最多的汽车</p>
          <div style="text-align:center ; line-height: 30px; font-size: 16px;">
            {{ result.topCar}}
          </div>
        </div>
        <div class="bg-color-black item">
            <p class="ml-3 colorBlue fw-b" style="text-align:center;">车辆最高销售额</p>
            <div style="text-align:center ; line-height: 30px; font-size: 16px;">
             {{ result.highVolume }}
            </div>
          </div>
         <div class="bg-color-black item">
            <p class="ml-3 colorBlue fw-b" style="text-align:center;">销售最多的车型</p>
            <div style="text-align:center ; line-height: 30px; font-size: 16px;">
              {{ result.mostModel }}
            </div>
          </div>
          <div class="bg-color-black item">
              <p class="ml-3 colorBlue fw-b" style="text-align:center;">车型最多品牌</p>
              <div style="text-align:center ; line-height: 30px; font-size: 16px;">
                {{result.mostBrand}}
              </div>
            </div>
            <div class="bg-color-black item">
                <p class="ml-3 colorBlue fw-b" style="text-align:center;">车辆平均价格</p>
                <div style="text-align:center ; line-height: 30px; font-size: 16px;">
                  {{ result.averagePrice }}
                </div>
              </div>
    </div>
    <div class="down">
      <div class="ranking bg-color-black">
        <span>
          <i class="iconfont icon-tongji2"></i>
        </span>
        <span class="fs-xl text mx-2 mb-1" style="font-size: 20px;">年度汽车排行榜</span>
        <dv-scroll-ranking-board class="dv-scr-rank-board" :config="ranking" v-bind:key="ranking.data[0].value"/>
      </div>
      <div class="percent">
        <div class="item bg-color-black">
          <span>汽油车占比率</span>
          <chart
            :tips="rate[0].tips"
            :colorObj="rate[0].colorData"
          />
        </div>
        <div class="item bg-color-black">
          <span>新能源占比率</span>
          <chart
            :tips="rate[1].tips"
            :colorObj="rate[1].colorData"
          />
        </div>
        <div class="water">
          
          <dv-water-level-pond class="dv-wa-le-po" :config="water" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive, onMounted } from 'vue'
import Chart from '../center/chart/draw'
import {inject, ref } from 'vue'
export default defineComponent({
  components: {
    Chart
  },
  setup() {
    // 下层数据
    const titleDate = [
      {
        number: 1020,
        text: '车辆的总数量'
      },
      {
        number: 18,
        text: '销售最多的汽车'
      },
      {
        number: 4,
        text: '车辆最高销售额'
      },
      {
        number: 71,
        text: '销量最多车型'
      },
      {
        number: 949,
        text: '车型最多品牌'
      },
      {
        number: 811,
        text: '车辆平均价格'
      },
    ]
    const titleItem = reactive([])

    const result=ref([])
    // const $axios=inject('$axios')
    const $axios = inject("$axios")
    //创建函数
    const getCarData = async () => { 
      const res = await $axios.get('myApp/center')
      result.value = res.data
      ranking.data = res.data.lastSortList
      //油车
      rate[0].tips = res.data.oilRate
      //电车
      rate[1].tips = res.data.tramRate
      //其他
      water.data=[res.data.otherRate]
      console.log(res);
      console.log(water.data);
    
    }

    // 初始化数据
    onMounted(() => {
      getCarData()
      setData()
    })

    const ranking = reactive({
      data: [
        {
          name: '周口',
          value: 55
        }
      ],
      carousel: 'single',
      unit: '辆'
    })

    const water = reactive({
      data: [24, 45],
      shape: 'roundRect',
      formatter: '{value}%',
      waveNum: 3
    })

    const rate = reactive([
      {
        id: 'centerRate1',
        tips: 60,
        colorData: {
          textStyle: '#3fc0fb',
          series: {
            color: ['#00bcd44a', 'transparent'],
            dataColor: {
              normal: '#03a9f4',
              shadowColor: '#97e2f5'
            }
          }
        }
      },
      {
        id: 'centerRate2',
        tips: 40,
        colorData: {
          textStyle: '#67e0e3',
          series: {
            color: ['#faf3a378', 'transparent'],
            dataColor: {
              normal: '#ff9800',
              shadowColor: '#fcebad'
            }
          }
        }
      }
    ])

    // 设置数据
    const setData = () => {
      titleDate.map(e => {
        titleItem.push({
          title: e.text,
          config: {
            number: [e.number],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 26
            }
          }
        })
      })
    }
    return {
      titleItem,
      ranking,
      water,
      rate,
      getCarData,
      result
    }
  }
})
</script>

<style lang="scss" scoped>
.center {
  display: flex;
  flex-direction: column;
  .up {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    .item {
      border-radius: 6px;
      padding-top: 8px;
      margin-top: 8px;
      width: 32%;
      height: 70px;
      .dv-dig-flop {
        width: 150px;
        height: 30px;
      }
    }
  }
  .down {
    padding: 6px 4px;
    padding-bottom: 0;
    width: 100%;
    display: flex;
    height: 255px;
    justify-content: space-between;
    .bg-color-black {
      border-radius: 5px;
    }
    .ranking {
      padding: 10px;
      width: 59%;
      .dv-scr-rank-board {
        height: 220px;
      }
    }
    .percent {
      width: 40%;
      display: flex;
      flex-wrap: wrap;
      .item {
        width: 50%;
        height: 120px;
        span {
          margin-top: 8px;
          font-size: 14px;
          display: flex;
          justify-content: center;
        }
      }
      .water {
        width: 100%;
        .dv-wa-le-po {
          height: 120px;
        }
      }
    }
  }
}
</style>
